ProfileHeader.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. "use client";
  2. import { UserInfoRep, UserVipInfo, Wallet, checkCodeApi } from "@/api/user";
  3. import {
  4. BalanceContent,
  5. BonusContent,
  6. FreeContent,
  7. ReplayContent,
  8. } from "@/components/ModalPopup/WalletDescribeModal";
  9. import TipsModal, { ModalProps } from "@/components/TipsModal";
  10. import { Link, useRouter } from "@/i18n/routing";
  11. import { useWalletStore } from "@/stores/useWalletStore";
  12. import { WalletEnum } from "@/types";
  13. import { vipImages } from "@/utils/constant";
  14. import { flatPoint, percentage } from "@/utils/methods";
  15. import { ProgressBar, Toast, Badge } from "antd-mobile";
  16. import { useTranslations } from "next-intl";
  17. import Image from "next/image";
  18. import { Fragment, useRef, useState } from "react";
  19. type Props = {
  20. userInfo: UserInfoRep;
  21. userMoney: Wallet;
  22. userVip: UserVipInfo;
  23. };
  24. const VipCard = (props: { userVip: UserVipInfo }) => {
  25. const { userVip } = props;
  26. const t = useTranslations("ProfilePage");
  27. // Vip 图标
  28. const vipIconElement = vipImages.map((item, index) => {
  29. if (item.leve === userVip.vip_level) {
  30. return (
  31. <Fragment key={index}>
  32. <Image src={item.src} alt={"vip"} height={110} width={100} />
  33. <span className={"icon-level"} style={{ color: item.color }}>
  34. {item.leve}
  35. </span>
  36. </Fragment>
  37. );
  38. }
  39. });
  40. return (
  41. <div className={"vip-card"}>
  42. <div className={"vip-card__icon"}>{vipIconElement}</div>
  43. <div className={"vip-card-process"}>
  44. {/*<div className={"process-top"}>{userVip.vip_exp}xp</div>*/}
  45. <div>
  46. <ProgressBar
  47. percent={percentage(userVip.vip_exp, userVip.vip_score_exp)}
  48. style={{
  49. "--fill-color": "#fb8b05",
  50. "--track-width": "0.0694rem",
  51. }}
  52. />
  53. </div>
  54. <div className={"process-bottom"}>
  55. <span>VIP{userVip.vip_level}</span>
  56. <span className={"process-bottom-desc"}>
  57. {t("expTips", {
  58. exp: flatPoint(userVip.vip_score_exp - userVip.vip_exp),
  59. })}
  60. </span>
  61. <span>
  62. VIP
  63. {userVip.vip_next_level}
  64. </span>
  65. </div>
  66. </div>
  67. </div>
  68. );
  69. };
  70. const WalletCard = (props: { userMoney: Wallet }) => {
  71. const { userMoney } = props;
  72. const t = useTranslations("ProfilePage");
  73. const tipsRef = useRef<ModalProps>(null);
  74. const [tipsStatus, setTipsStatus] = useState<keyof typeof WalletEnum>("Bonus");
  75. const modalHandler = (key: keyof typeof WalletEnum) => {
  76. setTipsStatus(key);
  77. tipsRef.current?.onOpen();
  78. };
  79. // 彩金、免费币、重玩币提现到钱包操作
  80. const handleAcquire = async () => {
  81. tipsRef.current?.onClose();
  82. // checkCodeApi({ code: "123", mobile: "18215519037" })
  83. // .then((res) => {
  84. // if (res.code === 200) {
  85. // Toast.show("领取成功!")
  86. // setTimeout(() => {
  87. // tipsRef.current?.onClose();
  88. // }, 1000)
  89. // return;
  90. // }
  91. // Toast.show("领取失败!");
  92. // })
  93. // .catch((error) => {
  94. // Toast.show("领取失败!");
  95. // });
  96. };
  97. return (
  98. <>
  99. <TipsModal
  100. ref={tipsRef}
  101. title={
  102. <div className={"flex items-center"}>
  103. <i
  104. className={"iconfont icon-liwuhuodong mr-[0.0694rem] text-[0.2778rem]"}
  105. ></i>
  106. {t("modalTitle")}
  107. </div>
  108. }
  109. >
  110. {/*现金*/}
  111. {tipsStatus === WalletEnum.Balance ? <BalanceContent wallet={userMoney} /> : null}
  112. {/* 彩金*/}
  113. {tipsStatus === WalletEnum.Bonus ? <BonusContent wallet={userMoney} handleAcquire={handleAcquire}/> : null}
  114. {/* 免费币 */}
  115. {tipsStatus === WalletEnum.Free ? <FreeContent wallet={userMoney} handleAcquire={handleAcquire}/> : null}
  116. {/* 重玩币 */}
  117. {tipsStatus === WalletEnum.Replay ? <ReplayContent wallet={userMoney} handleAcquire={handleAcquire}/> : null}
  118. </TipsModal>
  119. <div className="coin">
  120. <div className={"coin_right_wallet"}>
  121. <div
  122. className={"wallet_left_border"}
  123. onClick={() => modalHandler(WalletEnum.Balance)}
  124. >
  125. <span className="coin_left__icon iconfont icon-qianbao3"></span>
  126. <section>
  127. <div className={"wallet_header"}>
  128. <span>{t("balance")}</span>
  129. <Image
  130. className="wallet_header__icon"
  131. src="/img/a.png"
  132. alt="question"
  133. width={15}
  134. height={15}
  135. />
  136. </div>
  137. <div className="num">
  138. <span className="uppercase">brl </span>
  139. <span>{userMoney.score || 0.0}</span>
  140. </div>
  141. </section>
  142. </div>
  143. <div
  144. className={"wallet_right_content"}
  145. onClick={() => modalHandler(WalletEnum.Bonus)}
  146. >
  147. <Badge content={percentage(userMoney.current_point_rollover, userMoney.target_point_rollover) < 100 ? null : Badge.dot} style={{right: "10px"}}>
  148. <span className="coin_left__icon iconfont icon-qianbao3"></span>
  149. </Badge>
  150. <section>
  151. <div className={"wallet_header"}>
  152. {t("bonus")}
  153. <Image
  154. className="wallet_header__icon"
  155. src="/img/a.png"
  156. alt="question"
  157. width={15}
  158. height={15}
  159. />
  160. </div>
  161. <div className="num">
  162. <span className="uppercase">brl </span>
  163. <span>{userMoney.point || 0.0}</span>
  164. </div>
  165. </section>
  166. </div>
  167. <div
  168. className={"wallet_left_border"}
  169. onClick={() => modalHandler(WalletEnum.Free)}
  170. >
  171. <Badge content={percentage(userMoney.current_free_score_rollover, userMoney.target_free_score_rollover) < 100 ? null : Badge.dot} style={{right: "10px"}}>
  172. <span className="coin_left__icon iconfont icon-qianbao3"></span>
  173. </Badge>
  174. <section>
  175. <div className={"wallet_header"}>
  176. {t("free")}
  177. <Image
  178. className="wallet_header__icon"
  179. src="/img/a.png"
  180. alt="question"
  181. width={15}
  182. height={15}
  183. />
  184. </div>
  185. <div className="num">
  186. <span className="uppercase">brl </span>
  187. <span>{userMoney.free_score || 0.0}</span>
  188. </div>
  189. </section>
  190. </div>
  191. <div
  192. className={"wallet_right_content"}
  193. onClick={() => modalHandler(WalletEnum.Replay)}
  194. >
  195. <Badge content={percentage(userMoney.current_lose_score_rollover, userMoney.target_lose_score_rollover) < 100 ? null : Badge.dot} style={{right: "10px"}}>
  196. <span className="coin_left__icon iconfont icon-qianbao3"></span>
  197. </Badge>
  198. <section>
  199. <div className={"wallet_header"}>
  200. {t("replay")}
  201. <Image
  202. className="wallet_header__icon"
  203. src="/img/a.png"
  204. alt="question"
  205. width={15}
  206. height={15}
  207. />
  208. </div>
  209. <div className="num">
  210. <span className="uppercase">brl </span>
  211. <span>{userMoney.lose_score || 0.0}</span>
  212. </div>
  213. </section>
  214. </div>
  215. </div>
  216. </div>
  217. </>
  218. );
  219. };
  220. export const ProfileHeader = (props: Props) => {
  221. const { userInfo, userVip } = props;
  222. const t = useTranslations("ProfilePage");
  223. const wallet = useWalletStore((state) => state.wallet);
  224. const router = useRouter();
  225. const handler = () => {
  226. if (!!wallet.score) {
  227. router.push("/withdraw");
  228. } else {
  229. Toast.show("no money ");
  230. }
  231. };
  232. return (
  233. <>
  234. <div className={"userContent"}>
  235. <div className={"userInfo"}>
  236. <div>
  237. <div className={"bgImg"}>
  238. <Image
  239. src={"/img/avatar.png"}
  240. className={"h-[100%] w-[100%]"}
  241. alt={"avatar"}
  242. width={120}
  243. height={120}
  244. />
  245. </div>
  246. <div>
  247. <span>{t("Conta")}</span>
  248. <span className="phone">{userInfo?.user_phone || ""}</span>
  249. </div>
  250. </div>
  251. <Link className="goto iconfont icon-xiangzuo1" href={`/changePassword`}></Link>
  252. </div>
  253. {/*vipcard*/}
  254. <VipCard userVip={userVip} />
  255. <WalletCard userMoney={wallet} />
  256. </div>
  257. <div className="link">
  258. <Link href={"/deposit"} className={"btn"}>
  259. {t("Depósito")}
  260. </Link>
  261. <p className={"btn"} onClick={handler}>
  262. {t("Sacar")}
  263. </p>
  264. </div>
  265. </>
  266. );
  267. };